﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DataAccess
{
    public class DalCity
    {
        public static List<BusinessLogic.BizCity> getAll()  //get all cities
        {
            ViMapDataContext db = new ViMapDataContext();
            var cities = from city in db.Cities
                         select new BusinessLogic.BizCity
                         (
                            city.id,
                            city.Name
                         );
            return cities.ToList();
        }

        public static BusinessLogic.BizCity getCitybyId(int id)
        {
            ViMapDataContext db = new ViMapDataContext();
            var city = db.Cities.Single(p => p.id == id);
            return new BusinessLogic.BizCity
                        (
                            city.id,
                            city.Name,
                            Convert.ToDouble(city.Latitude),
                            Convert.ToDouble(city.Longitude),
                            Convert.ToDouble(city.north_east_Lat),
                            Convert.ToDouble(city.north_east_Lng),
                            Convert.ToDouble(city.south_west_Lat),
                            Convert.ToDouble(city.south_west_Lng)
                        );
        }

        public static List<BusinessLogic.BizPlace> getPlaceinCity(int cityId)
        {
            ViMapDataContext db = new ViMapDataContext();
            var places = from pla in db.Places
                         where pla.City == cityId
                         select new BusinessLogic.BizPlace
                         (
                            pla.id,
                            pla.Title,
                            Convert.ToDouble(pla.Latitude),
                            Convert.ToDouble(pla.Longitude),
                            pla.Website,
                            pla.Address,
                            pla.ContactPhone,
                            pla.Icon,
                            pla.Image
                         );
            return places.ToList();
        }
    }
}